import { cloneDeep } from "lodash"

/**
 * 将数据转为树形
 */
const dateTree = (data: any[], parentId: string = "superiorId", itemProp: string = "items", parentValue: string | null = null) => {
    const result: any[] = cloneDeep(data)
    const parentMenu = result.filter((parentItem) => {
        return parentItem[parentId] === parentValue
    })
    parentMenu.forEach((parentItem) => {
        parentItem[itemProp] = dateTree(data, parentId, itemProp, parentItem.id)
    })
    return parentMenu
}

/**
 * 暴露
 */
export {
    dateTree
}